import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:yt_devops/components/gaps.dart';
import 'package:yt_devops/components/yt_text_style.dart';
import 'package:yt_devops/styles/styles.dart';

class ItemTowCheckboxWidget extends StatefulWidget {
  final String title;
  final String firstString;
  final String value;
  final String secondString;
  final int status;
  final bool isShowDivider;
  final bool isRequired;
  final bool isEdit;//是否可以编辑不能编辑就只能查看
  final Color titleColor;
  final double titleSize;
  final Function(int) callBack;

  const ItemTowCheckboxWidget(this.title,this.firstString,this.secondString, this.status,
      this.callBack,{this.isShowDivider = false,this.isRequired =false,this.isEdit = true,
        this.titleColor = Colour.otherTextColor,this.titleSize = 14,this.value = '',Key? key}) : super(key: key);

  @override
  State<ItemTowCheckboxWidget> createState() => _ItemTowCheckboxWidgetState();
}

class _ItemTowCheckboxWidgetState extends State<ItemTowCheckboxWidget> {
  String title = '';
  String firstString= '';

  String secondString= '';
  int status = 1;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    title = widget.title;
    firstString = widget.firstString;
    secondString = widget.secondString;
    status = widget.status;
  }
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 50,
      color: Colors.white,
      child: Column(
        children: [
          Container(
            alignment: Alignment.centerLeft,
            margin: EdgeInsets.only( right: 16.w),
            height: 48,
            child: Row(
              children: [
                widget.isRequired
                    ? Container(
                  alignment: Alignment.center,
                  margin: EdgeInsets.only(
                    left: 6.w,
                    right: 2.w,
                  ),
                  child: Text(
                    '*',
                    style: ytTextStyle(
                      color: Colour.warningTextColor,
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                )
                    : Gaps.hGap16,
                Text(
                  title,
                  style: ytTextStyle(
                      fontWeight: FontWeight.normal,
                      color:widget.titleColor,
                      fontSize: widget.titleSize,),
                ),
                Spacer(),
                Visibility(
                    visible: widget.isEdit,
                    child: GestureDetector(
                        behavior: HitTestBehavior.opaque,
                        onTap: () {

                          setState(() {
                            status = 1;
                            widget.callBack(1);
                          });
                        },
                        child: Container(
                          padding: EdgeInsets.all(4),
                          child: Image.asset(
                            status == 1
                                ? 'assets/images/site_elec_price_selected.png'
                                : 'assets/images/site_elec_price_unselected.png',
                            height: 16,
                            width: 16,
                          ),
                        ))),
            Visibility(
              visible: widget.isEdit,
              child:Text(
                  firstString,
                  style: ytTextStyle(
                      fontWeight: FontWeight.normal,
                      color: status == 1
                          ? Colour.primaryColor
                          : Colour.mainTextColor,
                      fontSize: 14),
                )),
            Visibility(
              visible: widget.isEdit,
              child:Gaps.hGap16),
            Visibility(
              visible: widget.isEdit,
              child:GestureDetector(
                    behavior: HitTestBehavior.opaque,
                    onTap: () {
                      setState(() {
                        status = 0;
                        widget.callBack(0);
                      });
                    },
                    child: Container(
                      padding: EdgeInsets.all(4),
                      child: Image.asset(
                        status == 0
                            ? 'assets/images/site_elec_price_selected.png'
                            : 'assets/images/site_elec_price_unselected.png',
                        height: 16,
                        width: 16,
                      ),
                    ))),
            Visibility(
              visible: widget.isEdit,
              child:Text(
                  secondString,
                  style: ytTextStyle(
                      fontWeight: FontWeight.normal,
                      color:  status == 0
                          ? Colour.primaryColor
                          : Colour.mainTextColor,
                      fontSize: 14),
                )),

                Visibility(
                    visible: !widget.isEdit,
                    child:Text(
                      firstString,
                      style: ytTextStyle(
                          fontWeight: FontWeight.normal,
                          color:  Colour.mainTextColor,
                          fontSize: 14),
                    )),
              ],
            ),
          ),
          Visibility(
              visible: widget.isShowDivider,
              child: Container(
            height: 0.5,
            margin: EdgeInsets.only(left: 16.w, right: 16.w),
            color: Colour.dividerColor,
          )),
        ],
      ),
    );
  }
}
